package smoketest.undertow.config;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.env.ConfigurableEnvironment;
import org.springframework.core.env.EnumerablePropertySource;
import org.springframework.core.env.PropertySource;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;

/**
 * 读取aaa.yml的所有属性
 *
 * @author LaiMingWei
 * @version 3.2.1
 * @since 2025-06-24 0:00
 */
@Component
public class AllPropertiesReader {

	@Autowired
	private ConfigurableEnvironment env;

	@PostConstruct
	public void printAllProperties() {
		for (PropertySource<?> propertySource : env.getPropertySources()) {
			if (propertySource instanceof EnumerablePropertySource) {
				EnumerablePropertySource<?> eps = (EnumerablePropertySource<?>) propertySource;
				System.out.println("PropertySource: " + propertySource.getName());
				for (String key : eps.getPropertyNames()) {
					Object value = propertySource.getProperty(key);
					System.out.println(key + " = " + value);
				}
			}
		}
	}
}
